/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.mobbuzz.facade;

import edu.mobbuzz.bean.RSSChannel;
import edu.mobbuzz.storage.LabelRecordStore;
import edu.mobbuzz.storage.RSSChannelRecordStore;
import java.util.Vector;

public class RSSChannelFacade {
    private RSSChannelRecordStore rssChannelRS;
    private LabelRecordStore labelRS;
    private Vector rssChannelArray;
    
    public RSSChannelRecordStore getRssChannelRS() {
        if(rssChannelRS==null){
            rssChannelRS = new RSSChannelRecordStore();
        }
        return rssChannelRS;
    }

    public void setRssChannelRS(RSSChannelRecordStore rssChannelRS) {
        this.rssChannelRS = rssChannelRS;
    }

    
    public LabelRecordStore getLabelRS() {
        if(labelRS==null)
            labelRS = new LabelRecordStore();
        return labelRS;
    }

    public void setLabelRS(LabelRecordStore labelRS) {
        this.labelRS = labelRS;
    }

    public Vector getIdBySource (String source){
        return getRssChannelRS().getIdBySource(source);
    }

    public Vector getIndexBySource (String source){
        return getRssChannelRS().getIndexBySource(source);
    }
    
    public Vector displayRSSChannelList() {

        rssChannelArray = new Vector();

        /*if(getRssChannelRS().getNbRSSChannel()==0){
            RSSChannel rssChannel = new RSSChannel();
            rssChannel.setTitle("Detik.com");
            rssChannel.setSource("http://rss.detik.com/index.php/detikcom");
            rssChannel.setLabel("");
            getRssChannelRS().addRSSChannel(rssChannel);
        }*/
        
        if(getRssChannelRS().readRSRSSChannel()){
            for(int i=0;i<getRssChannelRS().getNbRSSChannel();i++){
                rssChannelArray.addElement(new RSSChannel(getRssChannelRS().rssChannelArr[i].getRecId(),
                                                          getRssChannelRS().rssChannelArr[i].getTitle(),
                                                          getRssChannelRS().rssChannelArr[i].getSource(),
                                                          getRssChannelRS().rssChannelArr[i].getLabel()));

            }
        }else{
            System.out.println("RS Contact Gagal dibuka");
        }


        return rssChannelArray;
    }
    
    public void addRSSChannel(RSSChannel rssChannel){
        getRssChannelRS().addRSSChannel(rssChannel);
    }

    public void deleteRSSChannel(int index){
         getRssChannelRS().deleteRSSChannel(index);
    }
    
    public void updateRSSChannel(int index, RSSChannel rssChannel){
         getRssChannelRS().updateRSSChannel(index, rssChannel);
    }
    
    public void closeRSSChannelRS(){
        getRssChannelRS().closeRecStore();
    }

    
    
}
